/********************************************************************************
*Function：errCode_t fpga(const char *fname)
*Description：fpga被动模式配置程序
*Input：
*Output：
*Return：errCode_t枚举类型
********************************************************************************/

#include"fpga.h"

errCode_t fpga(const char *fname)
{
	void *temp;
	int fd_dev, fd_conf, file_size;

	temp = malloc(DATA_NUM);
	memset(temp, 0, DATA_NUM);	
	//打开配置文件，读取配置信息并匹配值fpga
    	fd_conf = open(fname, O_RDWR);

	if(fd_conf < 0)
	{
	    perror("open source file.");
	    return OPEN_FILE_FAILURE;
	}
	else
	{
		file_size = read(fd_conf, temp, DATA_NUM);
		close(fd_conf);
	}

    	fd_dev = open("/dev/fpga", O_RDWR);
	if(fd_dev < 0)
	{
		perror("open fpga device.");
		return OPEN_DEV_FAILURE;
	}
	else
	{
		write(fd_dev, temp, file_size);
		close(fd_dev);
	}

    free(temp);

	return EXIT_SUC;
}




